<%--
    Document   : MTravels
    Created on : 04/05/2010, 14:10:08
    Author     : Jorge
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.Route"%>
<%@page import="br.terminalrodoviario.RouteTime"%>
<%@page import="br.terminalrodoviario.RouteTravel"%>
<%@page import="br.terminalrodoviario.Company"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Route" id="route" scope="page"/>
<jsp:useBean class="br.terminalrodoviario.Company" id="company" scope="session"/>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%
            if (company.getId() == 0) {
                response.sendRedirect("../login.jsp");
            }
            String id_route = request.getParameter("id_route");
            if (id_route != null) {
                route = new Route().selectById("Select r from Route r where r.id = " + id_route);
            }

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Guia Terminal Rodoviário</title>
        <style type="text/css">
            @import url("../../add/css/company.css");
            @import url("../../add/css/rodape.css");
        </style>
        <script type="text/javascript">
            var cont = 0;
            function buttonValidated(ischecked){
                if(ischecked==true){
                    cont++;
                }else{
                    cont--;
                }
                if(cont!=1)
                    document.getElementById("btnEditar").src = "../../add/images/botoes/btEditarDisable.png";
                else
                    document.getElementById("btnEditar").src = "../../add/images/botoes/btEditar.png";
                if(cont==0)
                    document.getElementById("btnRemover").src = "../../add/images/botoes/btRemoverDisable.png";
                else
                    document.getElementById("btnRemover").src = "../../add/images/botoes/btRemover.png";
                document.getElementById("btnEditar").disabled = cont != 1;
                document.getElementById("btnRemover").disabled = cont == 0;
            }
        </script>
    </head>
    <body>
        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho">
                        </div>
                    </td>
                </tr>
            </table>
            <table id="menuAdmin" width="762">
                <tr >
                    <td align="center">
                        <ul class="menuRota" >
                            <li class="current"><a href="MRoute.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuSolicitacao" >
                            <li><a href="MSolicitation.jsp" /></li>
                        </ul>
                    </td>
                </tr>
            </table>

            <div style="float:left">
                <br/>
                <b><a href="../index.jsp">Início</a> -> <a href="MRoute.jsp">Rotas</a></b>
                <br/><br/>
            </div>
            <div align="right" style="font-family:calibri; font-size:11px; font-style:inherit">
                <br/>Bem-vindo <b><%=request.getSession().getAttribute("username")%></b>,<br/>
                você está logado desde <%=request.getSession().getAttribute("date_session")%>h. ( <a href="../logout.jsp"><b>Logout</b></a> )<br/><br/>
            </div>

            <table  id="subTitulo">
                <tr>
                    <td id="icone">
                        &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../add/images/icones/route.png" alt="Rotas" title="Rotas"/>
                    </td>
                    <td>
                        Idas e Voltas
                    </td>
                </tr>
            </table>
            <form action="../RouteTravelServlet" method="post">
                <input type="hidden" value="<%=id_route%>" id="id_route" name="id_route"/>
                <table id="subMenu5">
                    <tr>
                        <td>
                            <ul class="btNovo2" >
                                <li><a href="../Fields/FRoute.jsp"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btEditar" >
                                <li><input id="btnEditar" type=image src="../../add/images/botoes/btEditarDisable.png" value="Editar" disabled="true" name="edit" title="Editar" alt="Editar"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btRemover" >
                                <li><input id="btnRemover" type=image src="../../add/images/botoes/btRemoverDisable.png" value="Remover" disabled="true" name="delete" title="Remover" alt="Remover"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btNovaIda" >
                                <li>
                                    <a href="../Fields/FRouteTime.jsp?route=<%=id_route%>&type=1">
                                        <img src="../../add/images/botoes/btNovaIda.png" title="Nova Ida" alt="Nova Ida" border="0"/>
                                    </a>
                                </li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btNovaVolta" >
                                <li>
                                    <a href="../Fields/FRouteTime.jsp?route=<%=id_route%>&type=2">
                                        <img src="../../add/images/botoes/btNovaVolta.png" title="Nova Volta" alt="Nova Volta" border="0"/>
                                    </a>
                                </li>
                            </ul>
                        </td>
                    </tr>
                </table>
                <br/>
                <br/>
                <div id="conteudo" align="center">
                    <%SimpleDateFormat formatBra = new SimpleDateFormat("HH:mm");%>
                    <%Collection<RouteTravel> lst = new RouteTravel().select("select r from RouteTravel r where r.route.id = " + route.getId() + " order by r.type asc");
                                if (lst != null && lst.size() != 0 && !lst.isEmpty()) {
                    %>
                    <table border="0" width="750" cellspacing="0" cellpadding="0">
                        <tr class="table_header">
                            <th></th>
                            <th align="left">Tipo</th>
                            <th align="left">De/Para</th>
                            <th align="left">Horário</th>
                        </tr>
                        <%
                            int i = 0;
                            int j = 0;
                            Object[] times = new RouteTime().select("from RouteTime rt where rt.routeTravel.route.id = " + route.getId() + " order by rt.routeTravel.type asc").toArray();
                            //out.println(times.length);
                            for (RouteTravel n : new RouteTravel().select("select r from RouteTravel r where r.route.id = " + route.getId() + " order by r.type asc")) {
                        %>
                        <tr class="<%=(i % 2 != 0) ? "table_row_bg" : "table_row"%>">
                            <td align="center" width="45"><input type="checkbox" name="id" onchange="buttonValidated(this.checked);" value="<%=n.getId()%>"/></td>
                            <td><a href="../Fields/FRouteTime.jsp?id=<%=n.getId()%>&route=<%=route.getId()%>"><%=n.getType() == 1 ? "Ida" : "Volta"%></a></td>
                            <td><%=n.getType() == 1 ? n.getRoute().getFrom().getFullName() + " - " + n.getRoute().getTo().getFullName() : n.getRoute().getTo().getFullName() + " - " + n.getRoute().getFrom().getFullName()%></td>
                            <td>
                                <%
                                    for (j = 0; j < times.length; j++) {
                                        RouteTime time = (RouteTime) times[j];
                                        if (time.getRouteTravel().getId() == n.getId()) //&& ((n.getType()==1 && time.getCity().getId() == n.getRoute().getFrom().getId())||(n.getType()==1 && time.getCity().getId() == n.getRoute().getTo().getId())))
                                        {
                                            out.print(formatBra.format(time.getTime()));
                                            break;
                                        }
                                    }
                                %>
                            </td>
                        </tr>
                        <%
                            }
                        %>
                    </table>
                    <%} else {%>
                    <h3>Não há nenhum registro.</h3>
                    <%}%>
                </div>
            </form>
            <table id="rodape" style="background-image:url(../../add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="../../Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="../../SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="../../Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
